package cn.jxau.fukin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jxau.fukin.dao.AdminMapper;
import cn.jxau.fukin.model.Admin;
import cn.jxau.fukin.model.AdminExample;
import cn.jxau.fukin.model.AdminExample.Criteria;
import cn.jxau.fukin.service.IAdminService;

@Service("adminService")
public class AdminService implements IAdminService {

	@Autowired
	AdminMapper adminMapper;

	@Override
	public List<Admin> queryAdminInfo(Admin admin) {
		AdminExample adminExample = new AdminExample();
		Criteria criteria = adminExample.createCriteria();
		judgeAdmin(admin, criteria);
		List<Admin> selectByExample = adminMapper.selectByExample(adminExample);
		return selectByExample;
	}

	private void judgeAdmin(Admin admin, Criteria criteria) {
		if (admin.getaId() != null && !"".equals(admin.getaId().trim()))
			criteria.andAIdEqualTo(admin.getaId());
		if (admin.getaName() != null && !"".equals(admin.getaName().trim()))
			criteria.andANameEqualTo(admin.getaName());
		if (admin.getaTelphone() != null && !"".equals(admin.getaTelphone().trim()))
			criteria.andATelphoneEqualTo(admin.getaTelphone());
		if (admin.getaPassword() != null && !"".equals(admin.getaPassword().trim()))
			criteria.andAPasswordEqualTo(admin.getaPassword());
		if (admin.getaIdentify() != null && !"".equals(admin.getaIdentify().trim()))
			criteria.andAIdentifyEqualTo(admin.getaIdentify());
	}
}
